package com.gcb.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.context.annotation.Configuration;

/**
 * @Author 35235
 * @Date 2021/7/21 11:45
 * @Version 1.0
 */
@Configuration
@Aspect
public class Advice {
    @Pointcut("execution(* com.gcb.service.impl.AccountServiceImpl.*(..))")
    public void pointCut1(){}
    @Around("pointCut1()")
    public Object runtimeAround(ProceedingJoinPoint pjp) throws Throwable {
        //执行签名
        Signature signature = pjp.getSignature();
        //获取执行类型（接口名）
        String targetClass = signature.getDeclaringTypeName();
        //获取执行操作名称（方法名）
        String targetMethod = signature.getName();
        //获取开始时间
        long beginTime = System.currentTimeMillis();
        //执行方法
        Object ret = pjp.proceed(pjp.getArgs());
        long endTime = System.currentTimeMillis();
        System.out.println(targetClass + " 中 " + targetMethod + " 运行时⻓ " +
                (endTime - beginTime) + "ms");
        return ret;

    }
}







